import React, { useMemo } from 'react'
import { usePlugin, RenderDropableWidget, useLayouts } from '@inbiz/react'
export default function RightPlugin({ IndexCode }: { IndexCode: string }) {
  const layouts = useLayouts('SearchResultEngine.RightPlugin');
  const index = useMemo(() => {
    let number = layouts.findIndex((item) => item.props.IndexCode == IndexCode);
    if (number != -1) {
      // 没有子节点时， 不显示
      if (!Object.keys(layouts?.[number]?.schema?.properties || {})?.length) {
        number = -1;
      }
    }
    return number;
  }, [IndexCode, layouts]);

  if (index >= 0) {
    return <RenderDropableWidget pluginName={'SearchResultEngine.RightPlugin'} pluginIndex={index} />;
  } else {
    return null;
  }
}
